const titleBar = document.querySelector('.title-bar');

let isMouseDown = false;
let offset = { x: 0, y: 0 };

// 鼠标按下事件
titleBar.addEventListener('mousedown', (e) => {
  isMouseDown = true;
  offset.x = e.x;
  offset.y = e.y;
});

// 鼠标移动事件
window.addEventListener('mousemove', async (e) => {
  if (!isMouseDown) return;

  // 获取当前窗口的位置
  const bounds = await window.electron.getCurrentWindowBounds();

  // 设置新的窗口位置
  window.electron.setWindowBounds({
    x: e.screenX - offset.x,
    y: e.screenY - offset.y,
    width: bounds.width,
    height: bounds.height,
  });
});

// 鼠标释放事件
window.addEventListener('mouseup', () => {
  isMouseDown = false;
});
